package com.owulia.leetcode.num.add;

public class AddTwoNumbers {

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode nodeTemp = new ListNode();
        ListNode node = nodeTemp;
        int carry = 0;
        ListNode emptyNode = new ListNode();
        emptyNode.val = 0;
        for (; ; ) {
            if (l1 == null) {
                l1 = emptyNode;
            }
            if (l2 == null) {
                l2 = emptyNode;
            }
            int sum = l1.val + l2.val + carry;
            nodeTemp.val = sum % 10;
            carry = sum / 10;
            l1 = l1.next;
            l2 = l2.next;
            if (null == l1 && null == l2 && carry <= 0) {
                break;
            } else {
                nodeTemp.next = new ListNode();
                nodeTemp = nodeTemp.next;
            }
        }
        return node;
    }

    public static void main(String[] args) {
        ListNode l1 = new ListNode();
        l1.val = 2;
    }
}
